package day12_thread_code.com.itheima.d7_thread_comunication;

public class Desk {
    private String data;
    public synchronized void get() throws InterruptedException {
        String name = Thread.currentThread().getName();
        if (data == null){
            this.notifyAll();
            this.wait();
        }else {
            System.out.println(name + "取走了：" + data);
            data = null;
            this.notifyAll();
            this.wait();
        }
    }

    public synchronized void put() throws InterruptedException {
        String name = Thread.currentThread().getName();
        if (data == null){
            data = name + "的数据";
            System.out.println(name + "放入了：" + data);
            this.notifyAll();
            this.wait();
        }else {
            this.notifyAll();
            this.wait();
        }
    }
}
